import notificationManager from '@ohos.notificationManager'
import wantAgent from '@ohos.app.ability.wantAgent'
export function getNowDateFormatter() {
  const nowDate = new Date()
  const year = nowDate.getFullYear()
  const month = nowDate.getMonth()+1
  const day = nowDate.getDate()
  const hour = nowDate.getHours()
  const minute = nowDate.getMinutes()
  const second = nowDate.getSeconds()
  return `${year}-${month<10?`0${month}`:month}-${day<10?`0${day}`:day} ${hour<10?`0${hour}`:hour}:${minute<10?`0${minute}`:minute}:${second<10?`0${second}`:second}`
}

export const sendNotice = async (data: any) => {
  let wantInfo: wantAgent.WantAgentInfo = {
    wants: [
      {
        bundleName: 'com.gongMao.zhiHuiYunGou',
        abilityName: 'EntryAbility',
      }
    ],
    requestCode: 0,
    operationType: wantAgent.OperationType.START_ABILITY,
    wantAgentFlags: [ wantAgent.WantAgentFlags.CONSTANT_FLAG ]
  }
  let request: notificationManager.NotificationRequest = {
    id: Math.floor(Math.random() * 10000),
    wantAgent: await wantAgent.getWantAgent(wantInfo),
    content: {
      contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
      normal: {
        title: data.title,
        text: data.text,
        additionalText: data.additionalText
      }
    },
    showDeliveryTime: true,
    deliveryTime: new Date().getTime(),
    groupName: 'wechat',
    slotType: notificationManager.SlotType.SOCIAL_COMMUNICATION
  }
  notificationManager.publish(request)
}